package com.iflytek.exam.service.impl;

import java.util.List;
import com.iflytek.common.utils.DateUtils;
import com.iflytek.exam.domain.CreateExam;
import com.iflytek.exam.mapper.CreateExamMapper;
import com.iflytek.exam.service.ICreateExamService;
import com.iflytek.exam.service.IExamTeacherService;
import com.iflytek.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iflytek.exam.mapper.ExamSetMapper;
import com.iflytek.exam.domain.ExamSet;
import com.iflytek.exam.service.IExamSetService;

/**
 * 试卷属性设置Service业务层处理
 *
 * @author Dogdog
 * @date 2024-07-09
 */
@Service
public class ExamSetServiceImpl implements IExamSetService
{
    @Autowired
    private ExamSetMapper examSetMapper;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private IExamTeacherService examTeacherService;
    @Autowired
    private ICreateExamService createExamService;



    /**
     * 查询试卷属性设置
     *
     * @param id 试卷属性设置主键
     * @return 试卷属性设置
     */
    @Override
    public ExamSet selectExamSetById(Long id)
    {
        return examSetMapper.selectExamSetById(id);
    }

    /**
     * 查询试卷属性设置列表
     *
     * @param examSet 试卷属性设置
     * @return 试卷属性设置
     */
    @Override
    public List<ExamSet> selectExamSetList(ExamSet examSet)
    {
        //TODO 到时候这个接口直接打开测试就行，逻辑已实现
        //1.这个是按照那个老师登录就让哪个老师查看自己创建的试卷
//        String name = SecurityContextHolder.getContext().getAuthentication().getName();//获取当前登录的用户id
//        Long userId = sysUserService.selectUserByUserName(name).getUserId(); //找到登录人的id
//        Long[] examIds = examTeacherService.selectExamIds(userId);
//        ExamSet examSet1 =examSetMapper.selectExamSetByIds(examIds);
//        return examSetMapper.selectExamSetList(examSet1);
        //2.所有用户登录都可以查看创建信息创建的试卷
        return examSetMapper.selectExamSetList(examSet);
    }

    /**
     * 新增试卷属性设置
     *
     * @param examSet 试卷属性设置
     * @return 结果
     */
    @Override
    public int insertExamSet(ExamSet examSet, Long examId)
    {
        examSet.setExamId(examId);
        examSet.setCreateTime(DateUtils.getNowDate());
        examSet.setCreateTime(DateUtils.getNowDate());
        return examSetMapper.insertExamSet(examSet);
    }

    /**
     * 修改试卷属性设置
     *
     * @param examSet 试卷属性设置
     * @return 结果
     */
    @Override
    public int updateExamSet(ExamSet examSet)
    {
        examSet.setUpdateTime(DateUtils.getNowDate());
        return examSetMapper.updateExamSet(examSet);
    }

    /**
     * 批量删除试卷属性设置
     *
     * @param ids 需要删除的试卷属性设置主键
     * @return 结果
     */
    @Override
    public int deleteExamSetByIds(Long[] ids)
    {
        return examSetMapper.deleteExamSetByIds(ids);
    }

    /**
     * 删除试卷属性设置信息
     *
     * @param id 试卷属性设置主键
     * @return 结果
     */
    @Override
    public int deleteExamSetById(Long id)
    {
        return examSetMapper.deleteExamSetById(id);
    }

    @Override
    public Boolean deleteExamSetByExamId(Long examId) {
        return examSetMapper.deleteExamSetByExamId(examId);
    }

    @Override
    public ExamSet selectExamSetByExamId(Long examId) {
        return examSetMapper.selectExamSetByExamId(examId);
    }

    @Override
    public ExamSet selectExamSetByExamIdAndUserId(Long examId, Long userId) {
        return examSetMapper.selectExamSetByExamIdAndUserId(examId,userId);
    }

}
